from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt, QString
from .msg_lamp import MsgLamp, MsgLamp_Button

#
# this is basically the standalone test for the lamps
# cut and pasted into a new class
#

class MsgHeader(QtGui.QWidget):
        def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)

		banner = QtGui.QLabel(self)
		banner.setGeometry(20, 20, 247, 86)
		path = "resources/messages_banner.png"
		banner.setPixmap(QtGui.QPixmap(path))

		self.toggles = []

		xoff = 270
		lamp = MsgLamp(self, "Urgent", "red")
		lamp.move(xoff,20)
		lamp.toggled.connect(self.toggled)
		self.toggles.append(lamp)

		lamp = MsgLamp(self, "Personal", "cyan")
		lamp.move(xoff,70)
		lamp.toggled.connect(self.toggled)
		self.toggles.append(lamp)

		xoff += 160
		lamp = MsgLamp(self, "Tarts", "pink")
		lamp.move(xoff,20)
		lamp.toggled.connect(self.toggled)
		self.toggles.append(lamp)

		lamp = MsgLamp(self, "Ruffians", "darkblue")
		lamp.move(xoff,70)
		lamp.toggled.connect(self.toggled)
		self.toggles.append(lamp)

		xoff += 160
		lamp = MsgLamp(self, "Houses", "green")
		lamp.move(xoff,20)
		lamp.toggled.connect(self.toggled)
		self.toggles.append(lamp)

		lamp = MsgLamp(self, "Adversaries", "yellow")
		lamp.move(xoff,70)
		lamp.toggled.connect(self.toggled)
		self.toggles.append(lamp)

		xoff += 170
		lamp = MsgLamp(self, "News", "purple")
		lamp.move(xoff,20)
		lamp.toggled.connect(self.toggled)
		self.toggles.append(lamp)

		lamp = MsgLamp(self, "Gossip", "darkorange")
		lamp.move(xoff,70)
		lamp.toggled.connect(self.toggled)
		self.toggles.append(lamp)

		xoff += 130
		lamp = MsgLamp_Button(self, "All")
		lamp.move(xoff,20)
		lamp.clicked.connect(self.all_on)

		lamp = MsgLamp_Button(self, "None")
		lamp.move(xoff,70)
		lamp.clicked.connect(self.all_off)



	toggled = QtCore.pyqtSignal(str, bool)

	def all_off(self):
		for lamp in self.toggles:
			lamp.turn_off()

	def all_on(self):
		for lamp in self.toggles:
			lamp.turn_on()


if __name__ == "__main__":

	def togg(what, how):
		print "{} set to {}".format(
			what, how
		)
	import sys
	app = QtGui.QApplication(sys.argv)

	font_db = QtGui.QFontDatabase()
	font_db.addApplicationFont("resources/Gabrielle.ttf")

#
#	use the wallpaper as the top level widget
#
	top = QtGui.QLabel()
	top.setGeometry(0, 0, 1024, 150)
	path = "resources/wood.jpg"
	top.setPixmap(QtGui.QPixmap(path))

	hdr = MsgHeader(top)
	hdr.toggled.connect(togg)

	top.show()
	sys.exit(app.exec_())
